// TypeScript file
module cl {

	export class Coord {
		public constructor(public x : number, public y : number) {
		}
	}

	export class Tile {
		public constructor(public x : number, public y : number) {
		}
	}

	export class Vector {
		public constructor(public x : number, public y : number) {
		}

		public len() : number {
			return Math.sqrt(this.x * this.x + this.y * this.y);
		}

		public unit() : Vector {
			let len = this.len();
			return new Vector(this.x / len, this.y / len);
		}

		public multiply(ratio : number) : Vector {
			return new Vector(this.x * ratio, this.y * ratio);
		}

		public asLength(len : number) : Vector {
			let ratio = len / this.len();
			return new Vector(this.x * ratio, this.y * ratio);
		}

		public verticalVectors() : Vector[] {
			return [
				new Vector(this.y, -this.x),
				new Vector(-this.y, this.x)
			];
		}

		public oppositeVector() : Vector {
			return new Vector(-this.x, -this.y);
		}

		public heading() : number {
			if (this.x == 0){
				return this.y > 0 ? 90 : -90;
			}else{
				return Math.atan2(this.y, this.x) / Math.PI * 180;
			}
		}

		public applyTo(coord : Coord) : Coord {
			return new Coord(coord.x + this.x, coord.y + this.y);
		}

		public static fromTo(from : Coord, to : Coord) : Vector {
			return new Vector(to.x - from.x, to.y - from.y);
		}
	}
}